﻿@page "/admin/listfavoritefolders"

@attribute [Authorize(Roles = "Admin")]


@inject IHttpService _httpService
@inject IPopupService PopupService
@inject NavigationManager NavigationManager

<MDCard>
    <DataTableCard TModel="FavoriteFolderOverviewModel" Headers="_headers" ApiUrl="@(_baseUrl)" ShowAddButton="false" Title="@($"{_name}列表")" @ref="dataTableCard">
        <ItemColContent>
            @if (context.Header.Value == "actions")
            {
                <MIcon Color="success"
                       Class="mr-2"
                       OnClick="()=>LookItem(context.Item)">@IconType.Look.ToIconString()</MIcon>
                <MIcon Color="info"
                       Class="mr-2"
                       OnClick="()=>EditItem(context.Item)">@IconType.Edit.ToIconString()</MIcon>
            }
            else if (context.Header.Value == nameof(FavoriteFolderOverviewModel.MainImage))
            {
                <CnGalWebSite.Shared.MasaComponent.PC.Admin.Users.Ranks.ImageChip Image="@context.Item.MainImage" />
            }
            else if (context.Header.Value == nameof(FavoriteFolderOverviewModel.UserId))
            {
                <CnGalWebSite.Shared.MasaComponent.PC.EditRecords.UserCenter.ReviewEditRecords.UserChip Id="@context.Item.UserId" Name="@context.Item.UserName" />
            }
            else if (context.Header.Value == nameof(FavoriteFolderOverviewModel.CreateTime))
            {
                @context.Item.CreateTime.ToString("yyyy-MM-dd HH:mm")
            }
            else if (context.Header.Value == nameof(FavoriteFolderOverviewModel.IsHidden))
            {
                <CnGalWebSite.Shared.MasaComponent.PC.Admin.Recommends.StateChip IsHidden=@context.Item.IsHidden />
            }
            else if (context.Header.Value == nameof(FavoriteFolderOverviewModel.ShowPublicly))
            {
                <CnGalWebSite.Shared.MasaComponent.PC.Admin.Entries.PlayedGames.ShowPubilcChip ShowPublicly=@context.Item.ShowPublicly />
            }
            else if (context.Header.Value == nameof(FavoriteFolderOverviewModel.IsDefault))
            {
                <CnGalWebSite.Shared.MasaComponent.PC.Admin.Favorites.Folders.StateChip IsDefault=@context.Item.IsDefault />
            }
            else
            {
                @context.Value
            }
        </ItemColContent>
    </DataTableCard>

</MDCard>



@code {
    private string _baseUrl = "api/Favorites/ListFavoriteFolders";
    private string _name = "收藏夹";

    private List<DataTableHeader<FavoriteFolderOverviewModel>> _headers = new List<DataTableHeader<FavoriteFolderOverviewModel>>
    {
        new ()
          {
            Text= "Id",
            Align= DataTableHeaderAlign.Start,
            Value= nameof(FavoriteFolderOverviewModel.Id)
          },
          new (){ Text= "名称", Value= nameof(FavoriteFolderOverviewModel.Name)},
          new (){ Text= "图片", Value= nameof(FavoriteFolderOverviewModel.MainImage)},
          new (){ Text= "用户", Value= nameof(FavoriteFolderOverviewModel.UserId)},
          new (){ Text= "创建时间", Value= nameof(FavoriteFolderOverviewModel.CreateTime)},
          new (){ Text= "数量", Value= nameof(FavoriteFolderOverviewModel.Count)},
          new (){ Text= "状态", Value= nameof(FavoriteFolderOverviewModel.IsHidden)},
          new (){ Text= "公开", Value= nameof(FavoriteFolderOverviewModel.ShowPublicly)},
          new (){ Text= "默认", Value= nameof(FavoriteFolderOverviewModel.IsDefault)},
          new (){ Text= "操作", Value= "actions",Sortable=false }
    };

    DataTableCard<FavoriteFolderOverviewModel> dataTableCard;

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }


    public void LookItem(FavoriteFolderOverviewModel model)
    {
        NavigationManager.NavigateTo("/favoritefolders/index/" + model.Id);
    }

    public void EditItem(FavoriteFolderOverviewModel model)
    {
        NavigationManager.NavigateTo("/space/EditSpaceFavoriteObjects?UserId=" + model.UserId + "&FolderId=" + model.Id);

    }
}
